import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PostgresSQL {

	public static void main(String[] argv) throws SQLException {

		System.out.println("-------- PostgreSQL "
				+ "JDBC Connection Testing ------------");

		try {

			Class.forName("org.postgresql.Driver");

		} catch (ClassNotFoundException e) {

			System.out.println("Where is your PostgreSQL JDBC Driver? "
					+ "Include in your library path!");
			e.printStackTrace();
			return;

		}

		System.out.println("PostgreSQL JDBC Driver Registered!");

		Connection connection = null;

		try {

			connection = DriverManager.getConnection(
					"jdbc:postgresql://127.0.0.1:5432/adempiere", "adempiere",
					"adempiere");

		} catch (SQLException e) {

			System.out.println("Connection Failed! Check output console");
			e.printStackTrace();
			return;

		}

		if (connection != null) {
			System.out.println("You made it, take control your database now!");
			PreparedStatement pstmt = connection.prepareStatement("SELECT COUNT(*) FROM  AD_WF_Process aw  WHERE aw.IsActive='Y' AND date_trunc('day',aw.Created)= '2011-03-14 00:00:00' AND aw.AD_Client_ID IN(0,11) AND aw.AD_Org_ID IN(50007,0,50004,50005,50006,50000,50001,50002,11,12) AND aw.AD_WF_Process_ID NOT IN ( SELECT Record_ID FROM AD_Private_Access WHERE AD_Table_ID = 645 AND AD_User_ID <> 101 AND IsActive = 'Y' )");
			Statement stmt = connection.createStatement();
//			pstmt.setString(1,"2011-03-24 00:00:00");
			ResultSet rset = pstmt.executeQuery();
			while (rset.next()) {
				System.out.println(rset.getString(1) + "   ");
			}
			stmt.close();
		} else {
			System.out.println("Failed to make connection!");
		}
	}

}